//
//  CallChangeViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/1.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "CallChangeViewController.h"

#import "TodoHttpManager.h"
#import "UserfulOneCell.h"
#import "UserfulPhoneTwoCell.h"
#import "UserfulThreeCell.h"
#import "UserfulForeCell.h"
#import "UserfulFiveCell.h"
//

#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#import "CellThreeView.h"

#import "AddMModel.h"
#import "FTPopOverMenu.h"
#import "ClientViewController.h"
#import "JobViewController.h"
@interface CallChangeViewController ()<UITableViewDelegate,UITableViewDataSource,UserfulForeCellDelegate,UITextFieldDelegate,UserfulThreeCellDelegate,UserfulFiveCellDelegate,UserfulOneCellDelegate,CellThreeViewDelegate,ABPeoplePickerNavigationControllerDelegate>
{
    
    NSMutableArray *_beiArr;
    NSMutableArray *_titlrArr;
    
    NSMutableArray *_keArr;
    NSMutableArray *_keOneArr;
    NSMutableDictionary *_zongCallDic;
    NSMutableArray *_denArr;
    NSMutableArray *_denJArr;
    NSMutableArray *_adArr;
    NSMutableArray *_adJArr;
    NSMutableArray *_tuiQArr;
    NSMutableArray *_tuiQOneArr;
    NSMutableArray *_tuiFArr;
    NSMutableArray *_tuiFOneArr;
    NSMutableArray *_xWuArr;
    NSMutableArray *_xWuYArr;
    NSMutableArray *_xMianArr;
    NSMutableArray *_xMianJArr;
    NSMutableArray *_xHuArr;
    NSMutableArray *_xHuXArr;
  
    
    NSString *_timeStr;//来访日期
    NSString *_keNameStr;//客户姓名
    NSString *_lianStr;//联系方式
    NSString *_sexStr;//性别
    NSString *_keDengStr;//客户等级
 

    NSString *_adStr;
    NSString *_tQStr;
    NSString *_tFStr;
    
    NSString *_tNameStr;
    NSString *_tPhoneStr;

  
    NSString *_xWStr;
    NSString *_xMianStr;
    NSString *_xHuStr;
    NSString *_poneStr;
    NSString *_xiaStr;
    
    NSString *phone_A ;
    NSString *phone_B;
    
    BOOL _isupdatelayout;
    
    CGFloat changeheight;
    
    NSMutableArray *_chuanCellArr;
  
    ABPeoplePickerNavigationController *_abPeoplePickerVc;
    
    UserfulPhoneTwoCell *_threecell;
}
@property (nonatomic,copy) NSString *tabString;

@property (nonatomic,strong) AddMModel *model;
@property (nonatomic,strong) DateModel *dModel;
@property(nonatomic,strong)NSMutableArray *seletedPhoneArry;
@property (nonatomic, strong) NSMutableArray         *pphoneArray;
//男女选择
@property (nonatomic,strong) NSString *sexString;
@property (nonatomic, strong) CellThreeView         *threeview;
@property(nonatomic,strong)UITableView *tabView;
@end

@implementation CallChangeViewController

-(void)viewWillAppear:(BOOL)animated
{
    //下拉菜单
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didCallTDGuDropDown:) name:TDGuDropDown object:nil];
    [_manager userGuWenDropDown];
    //修改来电
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDGuPhoneXiu:) name:TDGuPhoneXiu object:nil];
    
}

//下拉
-(void)didCallTDGuDropDown:(NSNotification *)notifi
{
    if (notifi.object != 0)
    {
        _zongCallDic = [notifi.object objectForKey:@"data"];
        //客户等级
        _denArr = [_zongCallDic objectForKey:@"khdj"];
        for (int i = 0; i < _denArr.count; i++)
        {
            NSDictionary *dict = [_denArr objectAtIndex:i];
            [_denJArr addObject:dict[@"content"]];
        }

        //广告推广
        _adArr = [_zongCallDic objectForKey:@"ggtg"];
        
        for (int i = 0; i < _adArr.count; i++)
        {
            NSDictionary *dict = [_adArr objectAtIndex:i];
            
            [_adJArr addObject:dict[@"content"]];
            
        }
        
        //推介渠道
        _tuiQArr = [_zongCallDic objectForKey:@"tjqd"];
        for (int i = 0; i < _tuiQArr.count; i++)
        {
            NSDictionary *dict = [_tuiQArr objectAtIndex:i];
            [_tuiQOneArr addObject:dict[@"content"]];
        }
        //推介方式
        _tuiFArr = [_zongCallDic objectForKey:@"tjfs"];
        for (int i = 0; i < _tuiFArr.count; i++)
        {
            NSDictionary *dict = [_tuiFArr objectAtIndex:i];
            [_tuiFOneArr addObject:dict[@"content"]];
            NSLog(@"------%@",_tuiFOneArr);
        }
              //需求物业
        _xWuArr = [_zongCallDic objectForKey:@"need_property"];
        for (int i = 0; i < _xWuArr.count; i++)
        {
            NSDictionary *dict = [_xWuArr objectAtIndex:i];
            [_xWuYArr addObject:dict[@"content"]];
        }
        //需求面积
        _xMianArr = [_zongCallDic objectForKey:@"order_area"];
        for (int i = 0; i < _xMianArr.count; i++)
        {
            NSDictionary *dict = [_xMianArr objectAtIndex:i];
            [_xMianJArr addObject:dict[@"content"]];
        }
        //需求户型
        _xHuArr = [_zongCallDic objectForKey:@"order_type"];
        for (int i = 0; i < _xHuArr.count; i++)
        {
            NSDictionary *dict = [_xHuArr objectAtIndex:i];
            [_xHuXArr addObject:dict[@"content"]];
        }
        
        
        [_tabView reloadData];
    }
 
}

//修改来电
-(void)didTDGuPhoneXiu:(NSNotification *)notifica
{
    if (notifica.object != 0)
    {
        int stutus = [[notifica.object objectForKey:@"status"] intValue];
        NSString *infoStr = [notifica.object objectForKey:@"info"];
        if (stutus == 1)
        {
            
            [_manager MakeMyselfAlert:infoStr andIsNeedTitle:NO andShowTime:2.0];
           // ClientViewController *clientVC = [[ClientViewController alloc] init];
          //  [self.navigationController pushViewController:clientVC animated:NO];
          //  JobViewController *job = [[JobViewController alloc] init];
            if (_isSecond==YES) {
                [self.navigationController popToRootViewControllerAnimated:YES];
            }else{
                [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
                //                JobViewController *job = [[JobViewController alloc] init];
                //                [self.navigationController pushViewController:job animated:NO];
                
            }

            [_tabView reloadData];
        }
        else
        {
             [_manager MakeMyselfAlert:infoStr andIsNeedTitle:NO andShowTime:2.0];
        }
    }
}

-(void)viewDidDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDGuDropDown object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDGuPhoneXiu object:nil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改来电";
    self.view.backgroundColor = [UIColor whiteColor];
    _manager = [TodoHttpManager sharedManager];
    _keArr = [NSMutableArray array];
    _keOneArr = [NSMutableArray array];
    _denArr = [NSMutableArray array];
    _denJArr = [NSMutableArray array];
    _tuiQArr = [NSMutableArray array];
    _tuiFOneArr = [NSMutableArray array];
    _tuiFArr = [NSMutableArray array];
    _tuiQOneArr = [NSMutableArray array];
    _xWuArr = [NSMutableArray array];
    _xWuYArr = [NSMutableArray array];
    _xMianArr = [NSMutableArray array];
    _xMianJArr = [NSMutableArray array];
    _xHuArr = [NSMutableArray array];
    _xHuXArr = [NSMutableArray array];
    _adArr = [NSMutableArray array];
    _adJArr = [NSMutableArray array];
    
    _beiArr = [NSMutableArray array];//
    _titlrArr = [NSMutableArray array];
    _chuanCellArr = [NSMutableArray array];
    
    
    _model = [[AddMModel alloc] init];
    _beiArr = [NSMutableArray arrayWithObjects:@"1",@"请输入客户姓名",@"请输入联系电话",@"1",@"1",@"1",@"1",@"1",@"请输入推荐人姓名",@"请输入推荐人电话",@"1",@"1",@"1",@"电话记录",@"1", nil];
    
    _titlrArr =[ NSMutableArray arrayWithObjects:@"来电日期:",@"客户姓名:",@"联系方式:",@"客户性别:",@"客户等级:",@"广告推广:",@"推广渠道:",@"推介方式:",@"推荐人姓名:",@"推荐人电话:",@"需求物业:",@"需求面积:",@"需求户型:",@"电话记录:",@"下次跟进日期:", nil];
    
    _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, B_HEIGHT) style:UITableViewStyleGrouped];
    _tabView.delegate = self;
    _tabView.dataSource = self;
    _tabView.rowHeight = 44;
    [self.view addSubview:_tabView];

    
    if (_cellDic != nil)
    {
        _timeStr = [_cellDic objectForKey:@"caller_time"];
        NSLog(@"====== riqi%@",_timeStr);
        _model.xingming = [_cellDic objectForKey:@"caller_name"];
        _model.fangshi = [_cellDic objectForKey:@"caller_phone"];
        _sexString = [_cellDic objectForKey:@"caller_sex"];
   
     
        
        _keDengStr = [_cellDic objectForKey:@"khdj"];
     
        _adStr = [_cellDic objectForKey:@"ggtg"];
        _tQStr = [_cellDic objectForKey:@"tjqd"];
        
        _tFStr = [_cellDic objectForKey:@"tjfs"];
        _model.tuiming = [_cellDic objectForKey:@"recommend_name"];
        _model.tuidianhua = [_cellDic objectForKey:@"recommend_phone"];
        
        _xWStr = [_cellDic objectForKey:@"need_property"];
        _xMianStr =[_cellDic objectForKey:@"order_area"];
        
        _xHuStr = [_cellDic objectForKey:@"order_type"];
      _model.baimiao = [_cellDic objectForKey:@"dhjl"];
        _xiaStr = [_cellDic objectForKey:@"remind_time"];
      
        phone_A = [_cellDic objectForKey:@"phone_a"];
        phone_B = [_cellDic objectForKey:@"phone_b"];
        NSLog(@"------其他的电话是---%@--%@",phone_A,phone_B);
        [self.seletedPhoneArry removeAllObjects];
        if (_model.fangshi.length>0) {
            [self.seletedPhoneArry addObject:_model.fangshi];
        }
        if (phone_A.length>0) {
            [self.seletedPhoneArry addObject:phone_A];
        }
        if (phone_B.length>0) {
            [self.seletedPhoneArry addObject:phone_B];
        }
        
        _chuanCellArr = [[NSMutableArray alloc] initWithObjects:_timeStr,_model.xingming,_model.fangshi,_sexString,_keDengStr,_adStr,_tQStr,_tFStr,_model.tuiming,_model.tuidianhua,_xWStr,_xMianStr,_xHuStr,_model.baimiao ,_xiaStr, nil];

        [_tabView reloadData];
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titlrArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==2) {
        if (self.seletedPhoneArry.count>=3) {
            return 150;
        }else if (self.seletedPhoneArry.count==2){
            return 100;
        }else{
            return 50;
        }
    }
    return 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0||indexPath.row == 14)
    {
        
        //带日历
        NSString *CellIdentifier1 = [NSString stringWithFormat:@"Cell%ld%ld", (long)[indexPath section], (long)[indexPath row]];
        UserfulOneCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
        if (cell == nil)
        {
            cell = [[UserfulOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
        }
        
        cell.delegate = self;
        cell.riLBtn.tag = indexPath.row;
        
        cell.firstLab.text = _titlrArr[indexPath.row];
        cell.timeLab.text = _chuanCellArr[indexPath.row];
        if (indexPath.row == 0)
        {
               cell.timeLab.text = _timeStr;
            
        }
        if (indexPath.row == 14)
        {
               cell.timeLab.text = _xiaStr;
        }
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return cell;
    }
    if (indexPath.row ==1||indexPath.row==2||indexPath.row==8||indexPath.row==9||indexPath.row==13)
    {
        //TextField
        NSString *CellIdentifier2 = [NSString stringWithFormat:@"Cell%ld%ld", (long)[indexPath section], (long)[indexPath row]];
        UserfulPhoneTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
        if (cell == nil)
        {
            cell = [[UserfulPhoneTwoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
        }
        
        cell.textViewBlock = ^(){
            
            NSLog(@"123");
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:7 inSection:0];
            
            //将要编辑的textfield 所在的cell  使其滚动到顶部的位置
            
            [_tabView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
            
        };
        
       // [cell setheadStr:nil andDetail:nil andModel:_model];
        cell.oneTF.delegate = self;
        cell.oneTF.tag = indexPath.row;
        [cell setPhoneheadStr:nil andDetail:nil andModel:_model];
        cell.firstLab.text = _titlrArr[indexPath.row];
        cell.oneTF.placeholder = _beiArr[indexPath.row];
        // cell.oneTF.text = _chuaFArr[indexPath.row];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        if (indexPath.row==1) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.layer.cornerRadius = 6;
            // btn.backgroundColor = [UIColor orangeColor];
            [btn setImage:[UIImage imageNamed:@"Btn_daoRu"] forState:0];
            [btn addTarget:self action:@selector(gotoAddressBookBtnClick1:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag = 1;
            [cell addSubview:btn];
//            _btn1 = btn;
//            _btn1.selected = NO;
//            [_exitArr addObject:_btn1];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(30, 30));
                make.right.equalTo(cell.contentView).offset(0);
                make.top.equalTo(cell.mas_top).offset(10);
            }];
        }
        if (indexPath.row==2) {
            cell.backgroundColor = [UIColor whiteColor];
            _threecell = cell;
            
            [cell.oneTF removeFromSuperview];
            [cell.firstLab removeFromSuperview];
            // self.threeview.tf1.text = phone_A;
            [cell.contentView addSubview:self.threeview];
            _threeview.delegate = self;
        }
        
        
        return cell;
        
    }
    if (indexPath.row == 3)
        
    {
        //男女选择
        NSString *CellIdentifier3 =@"CELL";
        UserfulThreeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier3];
        if (cell == nil)
        {
            cell = [[UserfulThreeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier3];
        }
        cell.firstLab.text = _titlrArr[indexPath.row];
        cell.sexStr = _sexStr;
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.delegate = self;
        
        return cell;
    }
    else
    {
        //下拉
        NSString *CellIdentifier4 = [NSString stringWithFormat:@"Cell%ld%ld", (long)[indexPath section], (long)[indexPath row]];
        UserfulForeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier4];
        if (cell == nil)
        {
            cell = [[UserfulForeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier4];
        }
        cell.firstLab.text = _titlrArr[indexPath.row];
        cell.selectBtn.tag = indexPath.row;
        cell.delegate = self;
        _tabString = _chuanCellArr[indexPath.row];
        [cell.selectBtn setTitle:_tabString.length>0?_tabString:@"无" forState:0];
        
        [cell.selectBtn addTarget:self action:@selector(visitSelectedBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return cell;
    }

}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame= CGRectMake(20, 25,B_WIDTH-20*2, 45);
    btn.layer.cornerRadius = 6;
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitle:@"保存" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    [btn addTarget:self action:@selector(phoneXiuGaiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    [self.view addSubview:view];
    return view;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    [self.view endEditing:YES];
    
}

- (void)gotoAddressBookBtnClick1:(UIButton *)btn{
    [self gotoAddressBookwithtag:btn.tag];
    
}
- (void)gotoAddressBookwithtag:(NSInteger )teger{
    
    _abPeoplePickerVc = [[ABPeoplePickerNavigationController alloc] init];
    _abPeoplePickerVc.peoplePickerDelegate = self;
    
    [self presentViewController:_abPeoplePickerVc animated:YES completion:nil];
    
}
#pragma mark - <ABPeoplePickerNavigationControllerDelegate>
// 当用户选中某一个联系人时会执行该方法,并且选中联系人后会直接退出控制器
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person
{
    // 1.获取选中联系人的姓名
    CFStringRef lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
    CFStringRef firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
    //CFStringRef abFullName = ABRecordCopyCompositeName(person);
    // (__bridge NSString *) : 将对象交给Foundation框架的引用来使用,但是内存不交给它来管理
    // (__bridge_transfer NSString *) : 将对象所有权直接交给Foundation框架的应用,并且内存也交给它来管理
    NSString *lastname = (__bridge_transfer NSString *)(lastName);
    NSString *firstname = (__bridge_transfer NSString *)(firstName);
    
    NSLog(@"%@ %@", lastname, firstname);
    if (lastname==nil&&firstName!=nil)
    {
        
        _model.xingming = [NSString stringWithFormat:@"%@",firstName];
    }
    else if (firstName==nil&&lastname!=nil) {
        
        _model.xingming = [NSString stringWithFormat:@"%@",lastName];
    }
    else
    {
        _model.xingming = [NSString stringWithFormat:@"%@%@",lastName,firstName];
    }
    //_username = lastname;
    
    // 2.获取选中联系人的电话号码
    // 2.1.获取所有的电话号码
    ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFIndex phoneCount = ABMultiValueGetCount(phones);
    
    NSMutableArray *tmparray = [NSMutableArray new];
    // 2.2.遍历拿到每一个电话号码
    for (int i = 0; i < phoneCount; i++) {
        if (phoneCount<=2) {
            // 2.2.1.获取电话对应的key
            NSString *phoneLabel = (__bridge_transfer NSString *)ABMultiValueCopyLabelAtIndex(phones, i);
            
            // 2.2.2.获取电话号码
            NSString *phoneValue = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phones, i);
            
            NSLog(@"phoneLabel:%@ ---- phoneValue:%@", phoneLabel, phoneValue);
            _model.fangshi = phoneValue;
            
            [tmparray addObject:phoneValue];
        }
        
        
    }
    //TODO：获取电话号码要做的事情
    
    _isupdatelayout = YES;
    changeheight = 150;
    //    [self.threeview reloadviewframe];
    [self.seletedPhoneArry removeAllObjects];
    
    self.seletedPhoneArry = [NSMutableArray arrayWithArray:tmparray];
    
    [self.threeview reloadviewwitharray:self.seletedPhoneArry];
    [self.tabView reloadData];
    self.pphoneArray = [NSMutableArray arrayWithArray:self.seletedPhoneArry];
}


#pragma mark - 改变tableview的位置（当将要编辑的时候）
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:textField.tag inSection:0];
    
    //将要编辑的textfield 所在的cell  使其滚动到中间的位置
    
    [_tabView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    
    return YES;
}


//键盘收回触发
- (void)textFieldDidEndEditing:(UITextField *)textField{
    //回归原处
    //    [self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
    // NSLog(@"----000   --  %@",textField.text);
    
    if (textField.tag == 1) {
        _model.xingming = textField.text;
    }else if (textField.tag == 2){
        _model.fangshi = textField.text;
    }else if (textField.tag == 8){
        _model.tuiming = textField.text;
    }else if(textField.tag == 9){
        _model.tuidianhua = textField.text;
    }else if (textField.tag == 13){
        _model.baimiao = textField.text;
    }else{
    }
    
}

#pragma  mark-- cell的代理方法
-(void)changeImageBtnClick:(UIButton *)sender
{
    
    if (sender.tag==50) {
        _sexString = @"1";//男
        
    }else{
        _sexString = @"2";//女
        
    }
}


//日历
-(void)riLiBtnClick:(UIButton *)sender withLab:(NSString *)riLiStr
{
    if (sender.tag == 0)
    {
        _timeStr = riLiStr;
        NSLog(@"00000000=====%@",_timeStr);
    }
    if (sender.tag == 14)
    {
        _xiaStr = riLiStr;
        NSLog(@"24242424242424 ---T ==%@",_xiaStr);
    }
}
#pragma mark 下拉的方法
-(void)visitSelectedBtnClick:(UIButton *)sender
{
    // NSLog(@"daijjideanniu =======%ld",sender.tag);
    if (sender.tag == 4)
    {
        [FTPopOverMenu showForSender:sender
                       withMenuArray:_denJArr
                          imageArray:nil
                           doneBlock:^(NSInteger selectedIndex)
         {
             [sender setTitle:_denJArr[selectedIndex] forState:UIControlStateNormal];
             _keDengStr =_denJArr[selectedIndex];
//             [sender setTitle:_denArr[selectedIndex][@"content"] forState:UIControlStateNormal];
//
//             _keDengStr =_denArr[selectedIndex][@"content"];
             [_chuanCellArr replaceObjectAtIndex:sender.tag withObject:_keDengStr];

             // NSLog(@"这是 ====== 等级=====%@",_keDengStr);
             
         }
                        dismissBlock:^
         {
             
         }];
    }
    
    else if (sender.tag == 5)
    {
        //广告推广
        [FTPopOverMenu showForSender:sender
                       withMenuArray:_adJArr
                          imageArray:nil
                           doneBlock:^(NSInteger selectedIndex)
         {
             [sender setTitle:_adJArr[selectedIndex] forState:UIControlStateNormal];
             _adStr = _adJArr[selectedIndex];
             [_chuanCellArr replaceObjectAtIndex:sender.tag withObject:_adStr];
             if (![_adStr isEqualToString:@"无"] && _adStr.length != 0) {
                 _tQStr =@"";
                 [_chuanCellArr replaceObjectAtIndex:6 withObject:@""];
             }
             [_tabView reloadData];
         }
                        dismissBlock:^
         {
             
         }];
    }
    else if (sender.tag == 6)
    {
        //推介渠道
        [FTPopOverMenu showForSender:sender
                       withMenuArray:_tuiQOneArr
                          imageArray:nil
                           doneBlock:^(NSInteger selectedIndex)
         {
//             [sender setTitle:_tuiQArr[selectedIndex][@"content"] forState:UIControlStateNormal];
             [sender setTitle:_tuiQOneArr[selectedIndex] forState:UIControlStateNormal];
//             _tQStr =_tuiQArr[selectedIndex][@"content"];
             _tQStr =_tuiQOneArr[selectedIndex];
             [_chuanCellArr replaceObjectAtIndex:sender.tag withObject:_tQStr];
             if (![_tQStr isEqualToString:@"无"] && _tQStr.length != 0) {
                 _adStr =@"";
                 [_chuanCellArr replaceObjectAtIndex:5 withObject:_adStr];
             }
             [_tabView reloadData];
         }
                        dismissBlock:^
         {
             
         }];
    }
    else if (sender.tag == 7)
    {
        //推介方式
        [FTPopOverMenu showForSender:sender
                       withMenuArray:_tuiFOneArr
                          imageArray:nil
                           doneBlock:^(NSInteger selectedIndex)
         {
             [sender setTitle:_tuiFOneArr[selectedIndex] forState:UIControlStateNormal];
             _tFStr =_tuiFOneArr[selectedIndex];
//             [sender setTitle:_tuiFArr[selectedIndex][@"content"] forState:UIControlStateNormal];
//             _tFStr = _tuiFArr[selectedIndex][@"content"];
             [_chuanCellArr replaceObjectAtIndex:sender.tag withObject:_tFStr];

         }
                        dismissBlock:^
         {
             
         }];
    }
        else if (sender.tag == 10)
    {
        //需求物业
        [FTPopOverMenu showForSender:sender
                       withMenuArray:_xWuYArr
                          imageArray:nil
                           doneBlock:^(NSInteger selectedIndex)
         {
             [sender setTitle:_xWuYArr[selectedIndex] forState:UIControlStateNormal];
             _xWStr =_xWuYArr[selectedIndex];
//             [sender setTitle:_xWuArr[selectedIndex][@"content"] forState:UIControlStateNormal];
//             _xWStr = _xWuArr[selectedIndex][@"content"];
             // NSLog(@"这点击的his=======%@",_iArr[selectedIndex][@"content"]);
             [_chuanCellArr replaceObjectAtIndex:sender.tag withObject:_xWStr];

         }
                        dismissBlock:^
         {
             
         }];
    }
    
    else if (sender.tag == 11)
    {
        //需求面积
        [FTPopOverMenu showForSender:sender
                       withMenuArray:_xMianJArr
                          imageArray:nil
                           doneBlock:^(NSInteger selectedIndex)
         {
             [sender setTitle:_xMianJArr[selectedIndex] forState:UIControlStateNormal];
             _xMianStr =_xMianJArr[selectedIndex];
//             [sender setTitle:_xMianArr[selectedIndex][@"content"] forState:UIControlStateNormal];
//             _xMianArr =_xMianArr[selectedIndex][@"content"];
             [_chuanCellArr replaceObjectAtIndex:sender.tag withObject:_xMianStr];

         }
                        dismissBlock:^
         {
             
         }];
    }
    
    
    else
    {
        //需求户型
        
        [FTPopOverMenu showForSender:sender
                       withMenuArray:_xHuXArr
                          imageArray:nil
                           doneBlock:^(NSInteger selectedIndex)
         {
             [sender setTitle:_xHuXArr[selectedIndex] forState:UIControlStateNormal];
             _xHuStr =_xHuXArr[selectedIndex];
//             [sender setTitle:_xHuArr[selectedIndex][@"content"] forState:UIControlStateNormal];
//             _xHuStr = _xHuArr[selectedIndex][@"content"];
             [_chuanCellArr replaceObjectAtIndex:sender.tag withObject:_xHuStr];

         }
                        dismissBlock:^
         {
             
         }];
        
        
    }
    
    
    
}



-(void)phoneXiuGaiBtnClick:(UIButton *)btn
{
    if (!_sexString) {
        _sexString = @"1";
    }
//    
//    NSLog(@"--------11111-----%@",_timeStr);
//    NSLog(@"--------11111-----%@",_model.xingming);
//    NSLog(@"--------11111-----%@",_model.fangshi);
//    NSLog(@"--------11111-----%@",_IDstr);
//    NSLog(@"--------11111-----%@",_IDAddStr);
//    NSLog(@"--------11111-----%@",_sexString);
//    NSLog(@"--------11111-----%@",_keDengStr);
//    NSLog(@"--------11111-----%@",_ageStr);
//    NSLog(@"--------11111-----%@",_adStr);
//    NSLog(@"--------11111-----%@",_tQStr);
//    NSLog(@"--------11111-----%@",_tFStr);
//    NSLog(@"--------11111-----%@",_model.tuiming);
    NSString *phone2 = @"";
    NSString *phone3 = @"";
    _model.fangshi = self.threeview.tf1.text;
    UserfulPhoneTwoCell *cell = (UserfulPhoneTwoCell *)[self.tabView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:13 inSection:0]];
    _model.baimiao = cell.oneTF.text;
    phone2 = self.threeview.tf2.text;
    phone3 = self.threeview.tf3.text;
    NSLog(@"%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@", _IDCall, _model.xingming, _model.fangshi, _xWStr, _xMianStr, _xHuStr, _sexString, _timeStr, _adStr, _tQStr, _tFStr, _model.tuiming, _model.tuidianhua, _model.baimiao, _xiaStr);
    //TODO:修改来访
    [_manager userGMXiuLaiDianWithID:_IDCall withName:_model.xingming withPhone:_model.fangshi withPhone_A:phone2 withPhone_B:phone3 withXWuYe:_xWStr withXArea:_xMianStr withXhouse:_xHuStr withSex:_sexString withCallTime:_timeStr withAD:_adStr withTQu:_tQStr withTWay:_tFStr withTName:_model.tuiming withTPhone:_model.tuidianhua withPhoneJ:_model.baimiao withNextTime:_xiaStr withKhdj:_keDengStr];
    

}
// type 1+2-
-(void)cellThreeViewBtnClickWithIndex:(NSInteger)index Type:(NSInteger)type{
    if (index==1) { // 1
        if (type==1) {//+
            [self.seletedPhoneArry replaceObjectAtIndex:0 withObject:_threeview.tf1.text];
            if (_threeview.tf2.text.length>0) {
                [self.seletedPhoneArry replaceObjectAtIndex:1 withObject:_threeview.tf2.text];
                [self.seletedPhoneArry addObject:@""];
            }else {
                [self.seletedPhoneArry addObject:@""];
            }
            
        }else{//-
            if (_threeview.tf3.text.length>0) {
                [self.seletedPhoneArry replaceObjectAtIndex:2 withObject:_threeview.tf3.text];
            }
            [self.seletedPhoneArry removeObjectAtIndex:0];
        }
    }else if (index==2){ // 2
        if (_threeview.tf3.text.length>0) {
            [self.seletedPhoneArry replaceObjectAtIndex:2 withObject:_threeview.tf3.text];
        }
        [self.seletedPhoneArry removeObjectAtIndex:1];
        
    }else{ // 3
        [self.seletedPhoneArry removeObjectAtIndex:2];
        
    }
    NSMutableArray *arr = [NSMutableArray arrayWithArray:self.seletedPhoneArry];
    [self.threeview reloadviewwitharray:arr];
    [self.tabView reloadData];
    self.pphoneArray = [NSMutableArray arrayWithArray:self.seletedPhoneArry];
}
-(CellThreeView *)threeview
{
    if (!_threeview)
    {
        CGFloat vHeight = 0;
        if (self.seletedPhoneArry.count>=3) {
            vHeight = 150;
        }else if (self.seletedPhoneArry.count==2){
            vHeight = 100;
        }else{
            vHeight = 50;
        }
        NSMutableArray *arr = [NSMutableArray arrayWithArray:self.seletedPhoneArry];
        _threeview = [[CellThreeView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, vHeight) witharray:arr];
        _threeview.backgroundColor = [UIColor whiteColor];
        _threeview.dataarray = arr;
        _isupdatelayout = NO;
        __weak __typeof(self) wself = self;
        
        _threeview.rerturnbtn = ^(CGFloat height) {
            _isupdatelayout = YES;
            changeheight = height;
            [wself changethreecellframewithheight:height];
            [wself.tabView reloadData];
        };
    }
    
    return _threeview;
}
-(NSMutableArray *)seletedPhoneArry
{
    if (!_seletedPhoneArry) {
        _seletedPhoneArry = [NSMutableArray array];
    }
    return _seletedPhoneArry;
}
- (void)changethreecellframewithheight:(CGFloat )height{
    CGRect frame = _threecell.frame;
    frame.size.height = height;
    _threecell.frame = frame;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
